package com.xsl.lession02.service;

import com.xsl.lession02.pojo.Route;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;


@Service
public class RouteService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private BaiduService baiduService;


    /**
     * 创建路线
     *
     * @return
     */
    public String createRoute(Long userId) {
        Route route = new Route();
        route.setId(ObjectId.get());
        route.setUserId(userId);
        route.setStatus(1);
        route.setIsShare(false);
        route.setStartTime(System.currentTimeMillis());

        //将数据保存到MongoDB
        this.mongoTemplate.save(route);

        String routeId = route.getId().toString();
        //百度地图鹰眼服务中创建Entity
        Boolean bool = this.baiduService.createEntity(routeId);
        if (bool) {
            //成功
            return routeId;
        }
        //失败
        return null;
    }

}
